import api from '@/api';
import * as types from '../mutation-types';

// initial state
const state = {
    balance: 0,
};

const mutations = {
    [types.QUERY_BALANCE](state, balance) {
        state.balance = balance;
    },
};

const getters = {
};

const actions = {
    queryBalance({ commit }) {
        api.repay.queryBalance().then((res) => {
            const { status, data, error } = res;
            if ('1' === status && '00000000' === error && data) {
                if (data.balance && !isNaN(data.balance)) {
                    commit(types.QUERY_BALANCE, data.balance);
                }
            }
        });
    },
};

export default {
    state,
    mutations,
    actions,
    getters
};
